

part of httpplugin;

extension HttpChannelExtension on HttpChannel {

  /// 取消请求
  void cancelRequest(int token){
    HttpMidBuffer.buffer.cancelRequestWidth(token);
  }

  /// 请求网络图片
  Future<HttpResultContainer> networkImage({required String url, Map<String, String>? header}){
    return HttpMidBuffer.buffer.requestWithParameter(AppRequest.networkImage, {
      HttpPluginKey.CUSTOMURL: url,
      HttpPluginKey.HEADER: header
    });
  }

  /// 上传图片
  Future<HttpResultContainer> uploadImage(dynamic image,
      {void Function(int count, int amount)? process,
        void Function(int? token)? cancelToken, required String token}) async{
    var value = await MultipartFile.fromFile(image);

    return HttpMidBuffer.buffer.uploadWithParameter(AppRequest.uploadImage, {
      HttpPluginKey.HEADER: {
        "content-type": "multipart/form-data",
        "token": token
      },
      HttpPluginKey.BODY: FormData.fromMap({
        "file": value
      })
    }, cancelToken: cancelToken, process: process);
  }
}

// 分页数
const int _pageSize = 15;